const db = require('../db/index')


// 获取宿舍列表
exports.getDormitoryList = async (req, res) => {
    try {
        const query = `
            select * from dormitories
        `;
        
        const [rows] = await db.query(query);
        console.log(rows);
        
        const dormitories = rows.map(row => ({
            id: row.id,
            name: row.name,
            address: row.address,
            capacity: row.capacity,
        }));
        
        res.send({
            status: 0,
            message: '获取宿舍列表成功',
            data: dormitories
        });
    } catch (error) {
        console.error(error);
        res.status(500).send({
            status: 1,
            message: '服务器错误'
        });
    }
}